﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;

namespace Bai2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        SinhVien sv = new SinhVien();
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

            dataGrid.SelectedValuePath = "Masv";
            dataGrid.ItemsSource = sv.DanhSachSinhVien().DefaultView;
        }


        private void Them_Click(object sender, RoutedEventArgs e)
        {
            DataView dv = (DataView)dataGrid.ItemsSource;


            string masv = textBox1.Text;
            string makhoa = textBox2.Text;
            string hosv = textBox3.Text;
            string ngaysinh = textBox4.Text;
            string tensv = textBox5.Text;
            string gioitinh = textBox6.Text;
            DataRowView row = dv.AddNew();
            row["Masv"] = masv;
            row["Hosv"] = hosv;
            row["Tensv"] = tensv;
            row["NgaySinh"] = ngaysinh;
            row["GioiTinh"] = gioitinh;
            row["MaKhoa"] = makhoa;

            sv.ThemSinhVien(masv, hosv, tensv, ngaysinh, gioitinh, makhoa);
            row.EndEdit();
            dataGrid.Items.Refresh();
        }

      
    }
}
